package com.mti.flexmusicplayer.model
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;

	public class PlayerModel extends EventDispatcher
	{
		private var _isPlaying:Boolean = false;
		[Bindable]
		public function get isPlaying():Boolean
		{
			return _isPlaying;
		}
		public function set isPlaying(value:Boolean):void
		{
			_isPlaying = value;
		}
		
		private var _currentMusic:MusicModel = null;
		[Bindable]
		public function get currentMusic():MusicModel
		{
			return _currentMusic;
		}
		public function set currentMusic(value:MusicModel):void
		{
			_currentMusic = value;
		}
		
		private var _channel:SoundChannel;
		[Bindable]
		public function get channel():SoundChannel
		{
			return _channel;
		}
		public function set channel(value:SoundChannel):void
		{
			_channel = value;
			var transform:SoundTransform = channel.soundTransform;
			transform.volume = volume / 100;
			channel.soundTransform = transform;
		}
		
		private var _pausePosition:Number = 0;
		public function get pausePosition():Number
		{
			return _pausePosition;
		}
		public function set pausePosition(value:Number):void
		{
			_pausePosition = value;
		}

		public function get position():int
		{
			if (isPlaying)
				return channel.position;
			return pausePosition;
		}
		
		private var _volume:Number = 50;
		[Bindable]
		public function get volume():Number
		{
			return _volume;
		}
		public function set volume(value:Number):void
		{
			_volume = value;
			var transform:SoundTransform = channel.soundTransform;
			transform.volume = volume / 100;
			channel.soundTransform = transform;
		}
	}
}